// 此处对ajax 进行了二次封装  => 调用ajax请求,返回进行中状态的Promise实例
function request (url, params = {}, type = "get") {
  return new Promise(function (resolve, reject) {
    $.ajax({
      type: type,
      url: url,
      data: { ...params },
      dataType: "json",
      success: function (data) { //形式参数(接口返回的响应数据 )
        resolve(data);
      }
    })
  })
}


const registered = params => request("../php/register.php", params);
const isExistPhone = params => request("../php/isExistPhone.php", params, "post");
const login = params => request("../php/login.php", params, "post");


//商品列表

const searchAllGoods = params => request("../php/searchAllGoods.php", params);

//排序
const searchGoodsOrder = params => request("../php/searchGoodsOrder.php", params);

// 商品详情
const searchGoodsByGoodsId = params => request("../php/searchGoodsByGoodsId.php", params);

//加入购物车
const addToShopingCar = params => request("../php/addToShopingCar.php", params, "post");

//加载购物车
const searchShoppingCarByUser = params => request("../php/searchShoppingCarByUser.php", params, "post");

// type = 0 => 减法   {type:0,id}
// type = 1 => 加法   {type:1,id}
// type = 2 => 失去焦点  直接改变内容  => buyNum   {type:2,id,buyNum}
const updateShoppingCarById = params => request("../php/updateShoppingCarById.php", params, "post");
const reduceGoods = params => request("../php/updateShoppingCarById.php", { type: 0, ...params }, "post");
const addGoods = params => request("../php/updateShoppingCarById.php", { type: 1, ...params }, "post");
const changeGoods = params => request("../php/updateShoppingCarById.php", { type: 2, ...params }, "post");

//删除
const delGoods = params => request("../php/deleteShoppingCarById.php", params, "post");

